//
//  CompleteDailyCell.m
//  ios-supplier
//
//  Created by feynmanyuan on 15/4/17.
//  Copyright (c) 2015年 feynmanyuan. All rights reserved.
//  绘制完成日期部分的cell
//

#import "CompleteDailyCell.h"

@interface CompleteDailyCell() {
    UILabel *_dateLabel;
    UILabel *_totalLabel;
    UILabel *_amountLabel;
}
@end

@implementation CompleteDailyCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier frame:(CGRect)frame{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.frame = frame;
        [self initSubView];
    }
    return self;
}

-(void)initSubView{
    _dateLabel = [[UILabel alloc] init];
    _dateLabel.font = [UIFont systemFontOfSize:TextFontSizeH4];
    _dateLabel.textColor = TextColorDefault;
    [self addSubview:_dateLabel];
    
    _totalLabel = [[UILabel alloc] init];
    _totalLabel.font = [UIFont systemFontOfSize:TextFontSizeH4];
    _totalLabel.textColor = TextColorDefault;
    [self addSubview:_totalLabel];
    
    _amountLabel = [[UILabel alloc] init];
    _amountLabel.font = [UIFont systemFontOfSize:TextFontSizeH4];
    _amountLabel.textColor = TextColorImportant;
    [self addSubview: _amountLabel];
    
    [self setBackgroundColor:PanelBgColorDefault];

}

-(void)setDaily:(JFBDailyDS *)daily{
    CGSize dateSize = [daily.date sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:TextFontSizeH4]}];
    CGFloat dateY = kDailyCellMargin;
    CGFloat dateX = kDailyCellMargin;
    CGRect dateRect = CGRectMake(dateX, dateY, dateSize.width, dateSize.height);
    _dateLabel.text = daily.date;
    _dateLabel.frame = dateRect;
    
    NSString *orderCount = [NSString stringWithFormat:@"%ld张订单", (unsigned long)daily.orderCount];
    CGSize totalSize = [orderCount sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:TextFontSizeH4]}];
    CGFloat totalY = kDailyCellMargin;
    CGFloat totalX = (self.bounds.size.width - totalSize.width) / 2;
    CGRect totalRect = CGRectMake(totalX, totalY, totalSize.width, totalSize.height);
    _totalLabel.text = orderCount;
    _totalLabel.frame = totalRect;
    
    
    NSString *amount = [NSString stringWithFormat:@"¥ %@", [NSString decimalToString:daily.orderAmount]];
    CGSize amountSize = [amount sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:TextFontSizeH4]}];
    CGFloat amountY = kDailyCellMargin;
    CGFloat amountX = self.bounds.size.width - amountSize.width - kDailyCellMargin;
    CGRect amountRect = CGRectMake(amountX, amountY, amountSize.width, amountSize.height);
    _amountLabel.text = [NSString stringWithFormat:@"¥ %@", [NSString decimalToString:daily.orderAmount]];
    _amountLabel.frame = amountRect;
    
    self.height = CGRectGetMaxY(_amountLabel.frame) + kDailyCellMargin;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
